//
//  JXMainViewController.swift
//  weibo
//
//  Created by admin on 16/5/19.
//  Copyright © 2016年 admin. All rights reserved.
//

import UIKit

class JXMainViewController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()
        
        addChildViewControllers()
        
        let mainTabBar = JXTabBar()
        
        mainTabBar.plusBtn.addTarget(self, action: #selector(plusBtnClick), forControlEvents: .TouchUpInside)
        
        
        
        setValue(mainTabBar, forKey: "tabBar")
        
        
        

    }
    
    @objc private func plusBtnClick(){
    
        print("我被点了")
    
    
    
    }
//tabs设置子控制器
    
    
    private func addChildViewControllers(){
    
        addChildViewController(JXHomeTableViewController(), title: "首页", imageName: "tabbar_home")
        
        addChildViewController(JXMessageTableViewController(), title: "消息", imageName: "tabbar_message_center")
        
        addChildViewController(JXDiscoverTableViewController(), title: "发现", imageName: "tabbar_discover")
        
        addChildViewController(JXProfileTableViewController(), title: "我的", imageName: "tabbar_profile")
    
    
    
    }
    
//nav设置根控制器
    private func addChildViewController(vc:UITableViewController, title:String, imageName:String){
    
        vc.title = title
        
        vc.tabBarItem.image = UIImage(named: imageName)
        
        vc.tabBarItem.selectedImage = UIImage(named: imageName + "_selected")?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
        vc.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName:UIColor.orangeColor()], forState: .Highlighted)
        
        let nav = JXNavViewController(rootViewController: vc)
        
        //设置tabbarItem的偏移量
        vc.tabBarItem.titlePositionAdjustment = UIOffset(horizontal: 0, vertical: -3)
        
        addChildViewController(nav)
    
    }



}
